package com.hbnu.test.www.net;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.nio.CharBuffer;

public class ReceiveThread implements Runnable{
    private DatagramSocket datagramSocket;
    public static void main(String[] args) {

    }

    @Override
    public void run() {
        try (DatagramSocket datagramSocket = new DatagramSocket();){
            while(true){
                byte[] bytes = new byte[1024];
                DatagramPacket datagramPacket = new DatagramPacket(bytes,bytes.length);
                datagramSocket.receive(datagramPacket);
                String ip = datagramPacket.getAddress().getHostAddress();
                int port = datagramPacket.getPort();
                byte[] data = datagramPacket.getData();
                String result = new String (data,0,datagramPacket.getLength());

                //现场考勤
//                new PrintWriter(new FileWriter(new File("D:")))

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
